package com.vastcom.demo.action;


import com.vastcom.demo.model.Carousel;
import com.vastcom.demo.model.Singlepage;
import com.vastcom.demo.service.ManageService;
import com.vastcom.demo.tools.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/public")

public class PublicAction {

    @Autowired
    private ManageService manageService;

    @GetMapping("getSinglePageList")
    @ResponseBody
    public HashMap getSinglePageList() throws Exception{
        HashMap m=new HashMap();
        try {
            List<Singlepage> sl=manageService.getSinglepageList();
            if(sl.size()>0){
                m.put("msg","ok");
                m.put("list",sl);
            }
            else {
                m.put("msg","empty");
            }
        } catch (Exception e) {
            e.printStackTrace();
            m.put("msg","error");
        }
        return m;
    }

    @GetMapping("getToken")
    @ResponseBody
    public HashMap getToken()throws Exception{
        HashMap m=new HashMap();

        String token= JwtUtil.generateToken("admin","admin456");
        m.put("token",token);
        return m;
    }


    @GetMapping("getCarouselList")
    @ResponseBody
    public HashMap getCarouselList()throws Exception{
        HashMap m=new HashMap();
        List<Carousel> cl=manageService.getCarouselList();
        if(cl.size()>0){
            m.put("msg","ok");
            m.put("list",cl);
        }
        else {
            m.put("msg","empty");
        }

        return m;
    }




}
